<%
# Joel Test plugin for Redmine
# Copyright (C) 2010  Takashi Takebayashi
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-%>
<h2><%= l(:joel_test) %></h2>
<div class="joel_test-plugin">
  <h3><%= l(:label_what_is_the_joel_test) %></h3>
  <p>
    <%= l(:text_what_is_the_joel_test) %><br />
    <%= l(:text_for_more_information_joel_test) %><br />
    <%= link_to(l(:label_joel_on_software), l(:label_joel_on_software_url), {:popup => true}) %>
  </p><%
unless (@target == nil) %>
  <p><%= l(:label_your_last_score) %> <%= @target.score %> <%= l(:label_score) %></p><%
end
unless (@targets.length == 0) %>
  <p><%= l(:label_average_score) %> <%= h(sprintf("%.2f", @average_score)) %> <%= l(:label_score) %></p><%
end %>
  <% form_tag :action => 'answer', :id => @project do %>
    <ol><%
@question_of_joel_test.each_with_index {|label, index|  # ジョエルテストの質問を表示する処理
  if (@target != nil) %>
      <li><%= l(label) %><br />
        <label><%= radio_button('question', (index + 1).to_s, 'yes', {:checked => @target.answers[index] != 0 ? 'checked' : 'false'}) %>Yes</label><label><%= radio_button('question', (index + 1).to_s, 'no', {:checked => @target.answers[index] != 1 ? 'checked' : 'false'}) %>No</label><%= "<br />
        <table class=\"yes-ratio\"><tr><th class=\"yes-ratio\">Yes率:</th><td class=\"yes-ratio\">" + progress_bar(@average_answers[index], {:width => '80px', :legend => "#{sprintf("%.2f", @average_answers[index]).to_f}%"}) + '</td></tr></table>' if (@targets.length != 0) %></li><%
  else %>
      <li><%= l(label) %><br />
        <label><%= radio_button('question', (index + 1).to_s, 'yes') %>Yes</label><label><%= radio_button('question', (index + 1).to_s, 'no') %>No</label><%= "<br />
        <table class=\"yes-ratio\"><tr><th class=\"yes-ratio\">Yes率:</th><td class=\"yes-ratio\">" + progress_bar(@average_answers[index], {:width => '80px', :legend => "#{sprintf("%.2f", @average_answers[index]).to_f}%"}) + '</td></tr></table>' if (@targets.length != 0) %></li><%
  end
} %>
    </ol>
    <p><%= submit_tag l(:button_answer), {:disabled => @permisson_answer_joel_test ? false : true, :disable_with => l(:label_loading)} %></p>
  <% end %>
</div><%
unless (@target == nil) %>
<div class="splitcontentleft">
  <h3><%= l(:label_your_recentry_score) %></h3><%
  if @reports.length == 0 %>
  <p><i><%= l(:label_no_data) %></i></p><%
  else %>
  <table class="list">
    <thead>
      <tr>
        <th style="width:50%"><%=l(:field_created_on)%></th>
        <th align="center" style="width:50%"><%=l(:field_score)%></th>
      </tr>
    </thead>
    <tbody><%
    @reports.each {|report| %>
      <tr class="<%= cycle("odd", "even") %>">
        <td align="center"><%= format_time(report.created_on) %></td>
        <td align="center"><%= report.score %></td>
      </tr><%
    } %>
    </tbody>
  </table><%
  end %>
</div>
<div id="joeltestgraph" class="splitcontentright"></div>
<!--[if IE]><script language="javascript" type="text/javascript" src="excanvas.min.js"></script><![endif]-->
<script type="text/javascript">
  $(document).ready(function() {
    var graph = [ <%= @graph %> ];
    var tick_data = [ '1', '2', '3', '4', '5' ];
    $.jqplot('joeltestgraph', [ graph ], {
      axes: {
        xaxis: {
          ticks: tick_data,
          renderer: $.jqplot.CategoryAxisRenderer
        },
        yaxis: {
          min: 0,
          max: 12,
          tickInterval: 2,
          numberTicks: 7
        }
      }
    });
  });
</script>
<% end %>
<% content_for :header_tags do -%>
<%= javascript_include_tag "jquery-1.3.2.min.js", :plugin => "redmine_joel_test" %>
<%= javascript_include_tag "jquery.jqplot.min.js", :plugin => "redmine_joel_test" %>
<%= javascript_include_tag "plugins/jqplot.categoryAxisRenderer.min.js", :plugin => "redmine_joel_test" %>
<% html_title(l(:joel_test)) -%>
<%= stylesheet_link_tag 'context_menu' %>
<% end -%>
